home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / Kelly Source / CapitalsMain.p < prev    next >
Encoding:
Text File  |  1989-11-12  |  3.2 KB  |  124 lines  |  [TEXT/PJMM]

  1. program DialogDemo;
  2.  
  3.     uses
  4.         Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, SANE, DialogHandlerHeader;
  5.  
  6.     const
  7.         DLog_ID = 10000;
  8.         DLogGotIt = 1;
  9.         DLogDone = 2;
  10.         DLogQUESTION = 3;
  11.         DLogANSWER = 4;
  12.         DLogPickUserItem = 5;
  13.         DLogUpdateUserItem = 6;
  14.         DLogComment = 7;
  15.  
  16.         CapitalListStrings = 1570;
  17.         CapitalStrings = 9042;
  18.         StateStrings = 2460;
  19.         numberofallstates = 50;
  20.  
  21.     var
  22.         stateindex, capitalindex: integer;
  23.         Capital: array[1..50] of integer;
  24.         Radiobuttonstatus: integer;
  25.         set1: RadioButtonSetPtr;
  26.         stcap, cities: str255;
  27.         currentstate: str255;
  28.  
  29.     function rand (limit: integer): integer;  {returns a random number between 1 and limit}
  30.  
  31.         var
  32.             secs, x: longint;
  33.     begin
  34.         GetDateTime(secs);
  35.         randseed := secs;
  36.         x := abs(random);
  37.         while x >= limit do
  38.             begin
  39.                 x := x div 10;
  40.             end;
  41.         x := x + 1;
  42.         rand := x;
  43.     end;
  44.  
  45.     procedure Mystartproc (dp: DialogPtr; itemHit: Integer; doubleclick: boolean; PickHandle: Listhandle; dhp: DialogHandlerRecordPtr);
  46.         var
  47.             i: integer;
  48.             Selectresult: boolean;
  49.             itemtype, ans: integer;
  50.             itemHandle: Handle;
  51.             itemRect: rect;
  52.  
  53.     begin
  54.         Stateindex := rand(numberofallstates);
  55.         GetIndString(currentstate, StateStrings, Stateindex);
  56.         PickHandle := DHGetPickListHandle(dhp, DLogPickUserItem);
  57.         DHEmptyPickList(PickHandle);
  58.         DHAddPickListStringList(PickHandle, CapitalListStrings);
  59.         DHAddStaticString(dhp, DLogQuestion, currentState);
  60.         GetDItem(dp, DLogQuestion, itemType, itemHandle, itemRect);
  61.         SetIText(itemHandle, currentState);
  62.     end;
  63.  
  64.     procedure GotIt (dp: DialogPtr; itemHit: Integer; dhp: DialogHandlerRecordPtr);
  65.         var
  66.             PickHandle: Listhandle;
  67.             Selectresult: boolean;
  68.             itemtype, ans: integer;
  69.             itemHandle: Handle;
  70.             itemRect: rect;
  71.  
  72.     begin
  73.         PickHandle := DHGetPickListHandle(dhp, DLogPickUserItem);
  74.         Selectresult := DHIsPickListItemSelected(PickHandle, capital[stateindex] - 1);
  75.         if Selectresult then
  76.             begin  {correct answer!}
  77.                 GetDItem(dp, DLogComment, itemType, itemHandle, itemRect);
  78.                 SetIText(itemHandle, 'Last Selection was correct!');
  79.                 MyStartProc(dp, itemHit, false, PickHandle, dhp);
  80.             end
  81.         else
  82.             begin  {wrong answer}
  83.                 GetDItem(dp, DLogComment, itemType, itemHandle, itemRect);
  84.                 SetIText(itemHandle, 'Last Selection was wrong!');
  85.             end;
  86.  
  87.     end;
  88.  
  89.     procedure DoThatDialog;
  90.         var
  91.             dhp: DialogHandlerRecordPtr;
  92.             i, offset: integer;
  93.     begin
  94.         DHNewRecord(dhp, DLog_ID, DefaultItem, DLogUpdateUserItem, NoCancelItem, NoSelectedItem);
  95.         DHShowArrowCursor;
  96.         DHAddPushButton(dhp, DLogDone, Exit);
  97.         DHAdvAddPushButton(dhp, DLogGotIt, NoExit, DHNoKeyEquiv, @GotIt);
  98.         DHAddPickList(dhp, DLogPickUserItem, @MyStartProc);
  99.         for i := 1 to 50 do
  100.             begin
  101.                 GetIndString(stcap, CapitalStrings, i);
  102.                 offset := 0;
  103.                 repeat
  104.                     begin
  105.                         offset := offset + 1;
  106.                         GetIndString(cities, CapitalListStrings, offset);
  107.                     end;
  108.                 until stcap = cities;
  109.                 capital[i] := offset;
  110.             end;
  111.         Stateindex := rand(numberofallstates);
  112.         GetIndString(currentstate, StateStrings, Stateindex);
  113.         DHAddStaticString(dhp, DLogQuestion, currentState);
  114.         DHSetCentering(dhp, True, True, SaveCenteringOff);
  115.         if DHDialogHandler(dhp) then
  116.             begin {user hit the OK}
  117.                   {End the program}
  118.             end;
  119.         DHDeallocateRecord(dhp);
  120.     end;
  121.  
  122. begin
  123.     DoThatDialog;
  124. end.